package com.report.repository;

import com.report.entity.AccountingProjectBalance;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AccountingProjectBalanceRepository extends JpaRepository<AccountingProjectBalance, Integer> {

    void deleteAllByProjectNoAndAuditCompanyUscc(String projectNo, String auditCompanyUscc);

    List<AccountingProjectBalance> findByAccountCodeAndAuditCompanyUscc(String accountCode, String auditCompanyUscc);

    List<AccountingProjectBalance> findByProjectTypeCodeAndAccountCodeAndAuditCompanyUscc(String projectTypeCode, String accountCode, String auditCompanyUscc);

    @Query(value = "select SUM(opening_debit_amount) from accounting_project_balance where project_type_code = :projectTypeCode and account_code = :accountCode and audit_company_uscc = :auditCompanyUscc", nativeQuery = true)
    String calculateAmountByProjectTypeCode(String projectTypeCode, String accountCode, String auditCompanyUscc);


    @Query(value = "select SUM(opening_debit_amount) from accounting_project_balance where project_code = :projectCode and account_code = :accountCode and audit_company_uscc = :auditCompanyUscc", nativeQuery = true)
    String calculateAmountByProjectCode(String projectCode, String accountCode, String auditCompanyUscc);
}
